Sometimes you want to break out of a loop early. Perhaps you have found what your loop is looking for, or something horrible has happened which means that it is pointless to continue. C provides a break keyword for just this situation. If you put a break into a loop the program is taken to the instruction which follows the end of the loop. You could call this "jumping out" of the loop, except that programming purists have a problem with jumps in programs.

The program in the Virtual CPIC would normally execute the loop 100 times. However I have added a conditional statement which will perform a break when i reaches 4. If you run the program you will see that when this line is reached the break is performed and the loop is terminated.

When you leave a loop the control variable is left at the value when the break occurred. This can be useful if your loop was searching down memory for something and you perform a break when you have found it. In this situation you would use the control variable to give you the value which has been reached.